package com.justplay.mobilelocation.UI;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.flyco.banner.anim.select.ZoomInEnter;
import com.flyco.banner.transform.DepthTransformer;
import com.justplay.mobilelocation.MainActivity;
import com.justplay.mobilelocation.R;
import com.justplay.mobilelocation.util.SharePreferencesUtil;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;


public class UserGuideActivity extends Activity {
    @Bind(R.id.sgb)
    SimpleGuideBanner sgb;
    private Context context = this;
    private View decorView;
    private boolean isFromBannerHome;
    private Class<? extends ViewPager.PageTransformer> transformerClass;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  WindowManager.LayoutParams.FLAG_FULLSCREEN);
//        2、 设置无title bar
        requestWindowFeature(Window.FEATURE_NO_TITLE);


        setContentView(R.layout.activity_user_guide);
        ButterKnife.bind(this);

        Boolean havedUse = SharePreferencesUtil.getBoolean("first", false, this);
        if (havedUse) {
            startActivity(new Intent(this,MainActivity.class));
            finish();
            return;
        }

        isFromBannerHome = getIntent().getBooleanExtra("isFromBannerHome", false);
        int position = getIntent().getIntExtra("position", -1);
        transformerClass = DepthTransformer.class;
        decorView = getWindow().getDecorView();
        sgb();
    }

    private void sgb() {

        sgb
                .setIndicatorWidth(6)
                .setIndicatorHeight(6)
                .setIndicatorGap(12)
                .setIndicatorCornerRadius(3.5f)
                .setSelectAnimClass(ZoomInEnter.class)
                .setTransformerClass(transformerClass)
                .barPadding(0, 10, 0, 10)
                .setSource(geUsertGuides())
                .startScroll();

        sgb.setOnJumpClickL(new SimpleGuideBanner.OnJumpClickL() {
            @Override
            public void onJumpClick() {
                if (isFromBannerHome) {
                    finish();
                    return;
                }
                SharePreferencesUtil.putBoolean("first", true, UserGuideActivity.this);


                Intent intent = new Intent(context, MainActivity.class);
                startActivity(intent);
                finish();
            }
        });
    }

    public static ArrayList<Integer> geUsertGuides() {
        ArrayList<Integer> list = new ArrayList<>();
        list.add(R.drawable.bg_page_01);
        list.add(R.drawable.bg_page_02);
        list.add(R.drawable.bg_page_03);
        list.add(R.drawable.bg_page_04);

        return list;
    }
}
